<?php

namespace Common\Model;

use Common\Lib\Upload\ImgManager;
use Think\Model;

class BbsImgModel extends Model
{
    protected $_auto = array(
        array('addtime', 'time', 1, 'function'),
    );

    public function get_list($map = '', $page = false, $sort = '', $num = 10)
    {
        $limit = $num ? $num : 10;

        if (empty($sort)) {
            $sort = 'id DESC';
        }
        if ($page) {
            $count    = $this->where($map)->count();
            $Page     = pager($count, $limit);
            $limit    = $Page->firstRow . ',' . $Page->listRows;
            $page_str = $Page->fshow();
        }

        $list = $this->where($map)->order($sort)->limit($limit)->select();
        foreach ($list as $key => $v) {
            //            $v['imgurl'] = $this->img_src($v['img']);
            $list[$key]['imgurl'] = uploadimgurl($v['img']);
        }

        $return['list']  = $list;
        $return['count'] = $page ? $count : count($list);
        $return['page']  = $page_str;

        return $return;
    }
}